﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;

namespace DCTLib.Common
{
    public class StringHelper
    {
        public static string Reverse(string str)
        {
            char[] chars = str.ToCharArray();
            Array.Reverse(chars);

            return new string(chars);
        }

        public static string Trim(string input)
        {
            if (input == null)
                input = "";
            return input.Trim();
        }

        public static string[] Split(string input, string delimiter)
        {
            return Regex.Split(input, Regex.Escape(delimiter));
        }       

        public static string StringConvertDecimal(decimal input)
        {
            NumberFormatInfo nfi = new NumberFormatInfo();
            nfi.NumberDecimalDigits = 2;
            nfi.NumberGroupSeparator = ",";
            try
            {
                return input.ToString("N", nfi);
            }
            catch
            {
                return input.ToString();
            }
        }

        public static string StringConvertUserNum(int input)
        {
            NumberFormatInfo nfi = new NumberFormatInfo();
            nfi.NumberDecimalDigits = 0;
            nfi.NumberGroupSeparator = ",";
            try
            {
                return input.ToString("N", nfi);
            }
            catch
            {
                return input.ToString();
            }
        }

        public static string StringConvertPoint(decimal input)
        {
            NumberFormatInfo nfi = new NumberFormatInfo();
            nfi.NumberDecimalDigits = 2;
            nfi.NumberGroupSeparator = ",";
            try
            {
                return input.ToString("N", nfi);
            }
            catch
            {
                return input.ToString();
            }
        }
    }
}
